{include file="header.htm" /}
<link href="__SKIN__/css/main.css?v={$version}" rel="stylesheet" type="text/css">
<link href="__SKIN__/css/page.css?v={$version}" rel="stylesheet" type="text/css">
<body class="bodystyle" style="cursor: default; -moz-user-select: inherit; min-width:400px;">
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<style type="text/css">
    .layui-layer-btn .layui-layer-btn0 {border-color: #4fc0e8 !important; background-color: #4fc0e8 !important;}
</style>
<div class="page" style="min-width: 400px;">
    {include file="bar.htm" /}
    <div class="flexigrid member_lt">
        <div class="mDiv" style="padding-top: 0;">
            <div class="ftitle_nav">
                <div class="fbutton">
                    <a href="{:weapp_url('DealerPlugin/DealerPlugin/dealer_index')}">
                        <div class="{eq name='$Request.param.sa' value='dealer_index'}cur{/eq}">
                            分销商列表
                        </div>
                    </a>
                </div>
                <div class="fbutton">
                    <a href="{:weapp_url('DealerPlugin/DealerPlugin/dealer_apply')}">
                        <div class="{eq name='$Request.param.sa' value='dealer_apply'}cur{/eq}">
                            分销商申请
                        </div>
                    </a>
                </div>
            </div>
        </div>
    </div>

    <div class="flexigrid flexigrid-xin">
        <div class="header-bar">
            <div class="more">
                <div class="search">
                    <div class="content">
                        <form id="searchForm" action="{:weapp_url('DealerPlugin/DealerPlugin/dealer_index')}" method="get" onsubmit="layer_loading('正在处理');" style="display: unset;">
                            {$searchform.hidden|default=''}
                            <input type="hidden" name="dealer_id" value="{$Request.param.dealer_id}">
                            <div class="ey-form-item"><label class="users-form-item-label">关键词：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <!-- 订单号查询 -->
                                            <div class="sDiv2">
                                                <input type="text" size="50" name="keywords" id="keywords" value="{$Request.param.keywords}" class="qsbox" style="width: 170px;" placeholder="搜索分销商/手机号...">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            
                            <div class="ey-form-item"><label class="users-form-item-label">分销商状态：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="">
                                                <select name="dealer_status" id="dealer_status">
                                                    <option value="" >全部</option>
                                                    <option value="1" {eq name="$Request.param.dealer_status" value="1"}selected{/eq}>正常</option>
                                                    <option value="2" {eq name="$Request.param.dealer_status" value="2"}selected{/eq}>冻结</option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>

                            <div class="ey-form-item"><label class="users-form-item-label">成为时间：</label>
                                <div class="users-form-item-content">
                                    <div class="users-select">
                                        <div tabindex="0" class="users-select-selection">
                                            <div class="sDiv2">
                                                <input type="text" name="add_time_begin" id="add_time_begin" autocomplete="off" value="{$Request.param.add_time_begin}" class="qsbox" placeholder="起始日期">
                                            </div>
                                            &nbsp;至&nbsp;
                                            <div class="sDiv2">
                                                <input type="text" name="add_time_end" id="add_time_end" autocomplete="off" value="{$Request.param.add_time_end}" class="qsbox" placeholder="结束日期">
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </form>
                        <div class="ey-form-item" style="margin-left: 20px;">
                            <div class="users-form-item-content">
                                <span class="bt-xin" onclick="dealerQuery();">查询</span>
                                <span class="bt-xin-no" onclick="dealerQuery('reset');">重置</span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div class="flexigrid member_lt" style="padding-top: 20px;">
        {empty name="dealerList"}
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%;">
                    <thead>
                        <tr>
                            <!-- <th axis="col4"> <div class="tl text-l10">会员名/会员昵称</div> </th> -->
                            <th axis="col4"> <div class="tl text-l10">会员昵称</div> </th>
                            <th axis="col4" class="w150"> <div class="tc">分销商姓名/手机号</div> </th>
                            <th axis="col4" class="w100"> <div class="tc">累计获得佣金</div> </th>
                            <th axis="col4" class="w120"> <div class="tc">上级分销商</div> </th>
                            <th axis="col4" class="w100"> <div class="tc">分销商级别</div> </th>
                            <th axis="col4" class="w110"> <div class="tc">分销商下级</div> </th>
                            <th axis="col4" class="w100"> <div class="tc">分销商状态</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">成为时间</div> </th>
                            <th axis="col4" class="w150"> <div class="tc">操作</div> </th>
                        </tr>
                    </thead>
                    <tbody>
                        
                    </tbody>
                </table>
                <div class="no_row" style="background: #FFF; width: auto;">
                    <div class="no_pic" style=" width: auto; line-height: 350px !important; height: 380px; text-align: center; margin: 0 auto; position: unset !important;"><img src="__SKIN__/images/null-data.png"></div>
                </div>
            </div>
        </div>
        {else/}
        <div class="hDiv">
            <div class="hDivBox">
                <table cellspacing="0" cellpadding="0" style="width: 100%;">
                    <thead>
                        <tr>
                            <!-- <th axis="col4"> <div class="tl text-l10">会员名/会员昵称</div> </th> -->
                            <th axis="col4"> <div class="tl text-l10">会员昵称</div> </th>
                            <th axis="col4" class="w150"> <div class="tc">分销商姓名/手机号</div> </th>
                            <th axis="col4" class="w100"> <div class="tc">累计获得佣金</div> </th>
                            <th axis="col4" class="w120"> <div class="tc">上级分销商</div> </th>
                            <th axis="col4" class="w100"> <div class="tc">分销商级别</div> </th>
                            <th axis="col4" class="w110"> <div class="tc">分销商下级</div> </th>
                            <th axis="col4" class="w100"> <div class="tc">分销商状态</div> </th>
                            <th axis="col4" class="w160"> <div class="tc">成为时间</div> </th>
                            <th axis="col4" class="w150"> <div class="tc">操作</div> </th>
                        </tr>
                    </thead>
                </table>
            </div>
        </div>
        <div class="bDiv" style="height: auto;">
            <div id="flexigrid" cellpadding="0" cellspacing="0" border="0">
                <table style="width: 100%">
                    <tbody>
                        {foreach name="dealerList" item="vo" key="k" }
                        <tr>
                            <td style="width: 100%">
                                <div class="pl10 text-l10 tl">
                                    <img id="img_head_pic" class="fl" style="width: 40px; height: 40px;" src="{$vo.head_pic|get_head_pic=###}">
                                    <!-- <p style="margin-top: -5px;"> <a href="JavaScript:void(0);" data-href="{:url('Member/users_edit', array('id'=>$vo['users_id']))}" onclick="openFullframe(this, '编辑会员', '100%', '100%');">{$vo.username}</a> </p>
                                    <p style="margin-top: -10px; color: #cccccc; font-size: 12px;"> <a href="JavaScript:void(0);" data-href="{:url('Member/users_edit', array('id'=>$vo['users_id']))}" onclick="openFullframe(this, '编辑会员', '100%', '100%');">{$vo.nickname}</a> </p> -->
                                    <p style="color: #cccccc; font-size: 12px;"> <a href="JavaScript:void(0);" data-href="{:url('Member/users_edit', array('id'=>$vo['users_id']))}" onclick="openFullframe(this, '编辑会员', '100%', '100%');">{$vo.nickname}</a> </p>
                                </div>
                            </td>

                            <td> 
                                <div class="w150 tc"> 
                                    <p style="margin-top: -5px;">{$vo.dealer_name} </p>
                                    <p style="margin-top: -10px;">{$vo.dealer_mobile}</p>
                                </div> 
                            </td>


                            <td> <div class="w100 tc"> {$vo.dealer_total_money} </div> </td>

                            <td>
                                <div class="w120 tc">
                                    {if condition='$vo.parentDealer.system_dealer == 1'}
                                    <p style="margin-top: -5px;" title="平台分销商，不参与订单分佣结算"> {$vo.parentDealer.dealer_name} </p>
                                    <p style="margin-top: -10px;" title="平台分销商，不参与订单分佣结算"> 平台分销商 </p>
                                    {elseif condition='$vo.parent_dealer_id != 0'/}
                                    <p style="margin-top: -5px;"> {$vo.parentDealer.dealer_name} </p>
                                    <p style="margin-top: -10px;"> {$vo.parentDealer.dealer_mobile} </p>
                                    {else/}
                                    无
                                    {/if}
                                </div>
                            </td>

                            <td align="center">
                                <div class="w100 tc">
                                    {if condition='$vo.parent_dealer_id eq 0'}一级分销商{else/}二级分销商{/if}
                                </div>
                            </td>

                            <td align="center">
                                <div class="w110 tc">
                                    {empty name="$vo.parent_dealer_id"}
                                    <p style="margin-top: -5px;">客户数： <a class="basics-color curpoin" href="JavaScript:void(0);" data-href="{:weapp_url('DealerPlugin/DealerPlugin/dealer_customer', ['users_id'=>$vo['users_id']])}" onclick="openFullframe(this, '分销商客户', '100%', '100%');">{$vo.subUsersNum}</a></p>
                                    <p style="margin-top: -10px;">二级分销商： <a class="basics-color curpoin" href="JavaScript:void(0);" data-href="{:weapp_url('DealerPlugin/DealerPlugin/dealer_subordinate', ['users_id'=>$vo['users_id']])}" onclick="openFullframe(this, '分销商下级', '100%', '100%');">{$vo.subDealerNum}</a></p>
                                    {else/}
                                    客户数： <a class="basics-color curpoin" href="JavaScript:void(0);" data-href="{:weapp_url('DealerPlugin/DealerPlugin/dealer_customer', ['users_id'=>$vo['users_id']])}" onclick="openFullframe(this, '分销商客户', '100%', '100%');">{$vo.subUsersNum}</a>
                                    {/empty}
                                </div>
                            </td>

                            <td>
                                {if condition='$dealerConfig.dealer_level eq 1 && $vo.parent_dealer_id neq 0'}
                                <div class="w100 tc">
                                    <span class="no" onclick="dealerTitle(this);" title="当前为一级分销商模式，已冻结所有二级分销商所有分销能力，如需开启二级分销商分销能力请选择 [分销设置]-[分销商层级]-[二级分销商]"><i class="fa fa-ban"></i></span>
                                </div>
                                {else/}
                                <div class="w100 tc">
                                    {if condition="$vo['dealer_status'] eq 1"}
                                    <span class="yes" onclick="dealerStatus({$vo.dealer_id}, 0);"><i class="fa fa-check-circle"></i>正常</span>
                                    {else /}
                                    <span class="no" onclick="dealerStatus({$vo.dealer_id}, 1);"><i class="fa fa-ban"></i>冻结</span>
                                    {/if}
                                </div>
                                {/if}
                            </td>

                            <td> <div class="w160 tc"> {$vo.add_time|MyDate='Y-m-d H:i:s',###} </div> </td>

                            <td class="operation">
                                <div class="w150 tc">
                                    <a class="btn red" href="JavaScript:void(0);" data-href="{:weapp_url('DealerPlugin/DealerPlugin/dealer_order', ['dealer_id'=>$vo['dealer_id']])}" onclick="openFullframe(this, '分销商订单', '100%', '100%');">订单</a>
                                    <i></i>
                                    <a class="btn red" href="JavaScript:void(0);" data-href="{:weapp_url('DealerPlugin/DealerPlugin/dealer_withdraw', ['dealer_id'=>$vo['dealer_id']])}" onclick="openFullframe(this, '分销商提现', '100%', '100%');">提现</a>
                                    <!-- <i></i>
                                    <a class="btn red" href="JavaScript:void(0);" onclick="dealerDel({$vo.dealer_id});">删除</a> -->
                                </div>
                            </td>
                        </tr>
                        {/foreach}
                    </tbody>
                </table>
            </div>
            <div class="iDiv" style="display: none;"></div>
        </div>
        {/empty}
        <div class="footer-oper">
            {$page}
            <div style="clear:both"></div>
        </div>
    </div>
</div>

<script type="text/javascript">
    layui.use('laydate', function() {
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#add_time_begin' //指定元素
        });
        laydate.render({
            elem: '#add_time_end' //指定元素
        });
    });

    function dealerTitle(obj) {
        var layer_str = $(obj).attr('title');
        layer.confirm(layer_str, {
            shade: layer_shade,
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['已知晓'],
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        });
    }

    // 分销商状态处理
    function dealerStatus(dealer_id, dealer_status) {
        if (0 === parseInt(dealer_status)) {
            var msg = '确认冻结分销商？冻结后分销商不参与订单结算分佣！';
        } else if (1 === parseInt(dealer_status)) {
            var msg = '确认恢复分销商？恢复后分销商参与订单结算分佣！';
        }
        layer.confirm(msg, {
            shade: layer_shade,
            area: ['480px', '190px'],
            move: false,
            title: '提示',
            btnAlign:'r',
            closeBtn: 3,
            btn: ['确认','取消'], //按钮
            success: function () {
                $(".layui-layer-content").css('text-align', 'left');
            }
        }, function() {
            layer_loading("正在处理");
            $.ajax({
                type: 'post',
                url : "{:weapp_url('DealerPlugin/DealerPlugin/dealer_status', ['_ajax'=>1])}",
                data: {dealer_id: dealer_id, dealer_status: dealer_status},
                dataType: 'json',
                success: function(res) {
                    layer.closeAll();
                    if (res.code == 1) {
                        layer.msg(res.msg, {time: 1000}, function() {
                            window.location.reload();
                        });
                    } else {
                        showErrorMsg(res.msg);
                    }
                },
                error: function(e){
                    layer.closeAll();
                    showErrorAlert(e.responseText);
                }
            });
        }, function(index) {
            layer.closeAll(index);
        });
    }

    // 分销商查询
    $(document).keydown(function(event) {
        if (event.keyCode == 13) {
            $('#searchForm input[type=text]').each(function(index, item) {
                if ($(item).is(':focus')) dealerQuery();
            });
        }
    });

    function dealerQuery(isReset) {
        if (isReset && 'reset' == isReset) {
            window.location.href = "{:weapp_url('DealerPlugin/DealerPlugin/dealer_index')}";
        } else {
            $('#searchForm').submit();
        }
    }
</script>

{include file="footer.htm" /}